package com.atguigu.tingshu.search.listener;/*
 * title:
 * author:
 * date:
 * description:
 * */

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.search.service.SearchService;
import io.micrometer.common.util.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class SearchListener {
    @Resource
    SearchService searchService;
    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_UPPER)
    public void upper(String albumId, Acknowledgment acknowledgment){
        if (StringUtils.isBlank(albumId)){
            acknowledgment.acknowledge();
            return;
        }
        searchService.upper(Long.valueOf(albumId));
        acknowledgment.acknowledge();
    }

    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_LOWER)
    public void lower(String albumId, Acknowledgment acknowledgment){
        if (StringUtils.isBlank(albumId)){
            acknowledgment.acknowledge();
            return;
        }
        searchService.lower(albumId);
        acknowledgment.acknowledge();
    }
}
